<template>
	<view class="container">
		<view class="page-body">
			<scroll-view class="nav-left" scroll-y :style="'height:'+height+'px'">
				<view class="nav-left-item" @click="categoryClickMain(item,index)" :key="index" :class="index==categoryActive?'active':''"
				    v-for="(item,index) in categoryList">
					{{item.name}}
				</view>
			</scroll-view>
			<scroll-view class="nav-right" scroll-y :scroll-top="scrollTop" :style="'height:'+height+'px'" scroll-with-animation>
				<view v-for="(cate, index) in subCategoryList" :key="index">
					<view class="g-subCate-name"><text>{{cate.name}}</text></view>
					<navigator open-type="navigate" class="g-cate-item" v-for="(item,idx) in cate._child" :key="idx" :url="'/pages/ydt/search_list?id='+item.id">
						<image :src="item.thumb_text" />
						<view>{{item.name}}</view>
					</navigator>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import henglang from '../../common/common.js';
	export default {
		data() {
			return {
				categoryList: [],
				subCategoryList: [],
				height: 0,
				categoryActive: 0,
				scrollTop: 0,
				scrollHeight: 0,
				isGoodType: henglang.isGoodsTpye()
			}
		},
		methods: {
			scroll(e) {
				this.scrollHeight = e.detail.scrollHeight;
			},
			categoryClickMain(categroy, index) {
				this.categoryActive = index;
				this.subCategoryList = categroy._child;
				this.scrollTop = -this.scrollHeight * index;
			},
			getCategory() {
				let that = this
				henglang.get('goods/getGoodsCategory',{},false,function(res){
					that.categoryList = res.data.data;
					that.subCategoryList = that.categoryList[0]._child;
				});
			}
		},
		onLoad() {
			this.getCategory();
			this.height = uni.getSystemInfoSync().windowHeight;
		}
	}
</script>

<style>
	.page-body {
		display: flex;
	}

	.nav {
		display: flex;
		width: 100%;
	}

	.nav-left {
		width: 30%;
		background: #f8f8f8;
		color: #828080;
	}

	.nav-left-item {
		height: 100upx;
		font-size: 30upx;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.nav-right {
		width: 70%;
	}

	.active {
		color: #D71611;
		font-size: 34upx;
	}
	
    .g-subCate-name {
        color: #474747;
        padding: 20upx 0;
        display: flex;
        justify-content: center;
        align-items: center;
    }
    .g-subCate-name text {
        margin: 0 20upx;
		font-size: 28upx;
    }
    .g-subCate-name::before {
        content: '';
        display: block;
        width: 70upx;
        height: 1px;
        background: #808080;
    }
    .g-subCate-name::after {
    	content: '';
    	display: block;
    	width: 70upx;
    	height: 1px;
    	background: #808080;
    }
	.g-cate-item {
	    display: inline-flex;
	    width: 33.333%;
	    flex-direction: column;
	    align-items: center;
	    justify-content: center;
		vertical-align: top;
	    font-size: 24upx;
	    color: #000;
	    margin-bottom: 10px;
		height: 170upx;
		overflow: hidden;
	}
	.g-cate-item image {
	    width: 75%;
	}
</style>
